﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WindowsGame1
{

    public enum Abilities
    {
        Strength = 0,
        Stamina = 1,
        Agility = 2,
        Speed = 3,
        Intellect = 4,
        Luck = 5
    };

    class CharacterAbilities
    {
        const float minAbilityScore = 0f;
        const float maxAbilityScore = 200f;
        int strength;
        int stamina;
        int agility;
        int speed;
        int intellect;
        int luck;

        public CharacterAbilities()
        {
            foreach (Abilities a in Enum.GetValues(typeof(Abilities)))
                SetAbilityScore(a, 10);
        }

        public int this[Abilities index]
        {
            get { return GetAbilityScore(index); }
            set { SetAbilityScore(index, value); }
        }

        public int this[int index]
        {
            get { return GetAbilityScore((Abilities)index); }
            set { SetAbilityScore((Abilities)index, value); }
        }

        public int Length
        {
            get
            {
                return Enum.GetNames(typeof(Abilities)).Length;
            }
        }

        public int Strength
        {
            get { return strength; }
            set
            {
                strength = (int)MathHelper.Clamp(value,
                    minAbilityScore,
                    maxAbilityScore);
            }
        }

        public int Stamina
        {
            get { return stamina; }
            set
            {
                stamina = (int)MathHelper.Clamp(value,
                minAbilityScore,
                maxAbilityScore);
            }
        }

        public int Agility
        {
            get { return agility; }
            set
            {
                agility = (int)MathHelper.Clamp(value,
                minAbilityScore,
                maxAbilityScore);
            }
        }

        public int Speed
        {
            get { return speed; }
            set
            {
                speed = (int)MathHelper.Clamp(value,
                minAbilityScore,
                maxAbilityScore);
            }
        }

        public int Intellect
        {
            get { return intellect; }
            set
            {
                intellect = (int)MathHelper.Clamp(value,
                minAbilityScore,
                maxAbilityScore);
            }
        }

        public int Luck
        {
            get { return luck; }
            set
            {
                luck = (int)MathHelper.Clamp(value,
                minAbilityScore,
                maxAbilityScore);
            }
        }

        private int GetAbilityScore(Abilities index)
        {
            if (index == Abilities.Strength)
                return strength;
            if (index == Abilities.Stamina)
                return stamina;
            if (index == Abilities.Agility)
                return agility;
            if (index == Abilities.Speed)
                return speed;
            if (index == Abilities.Intellect)
                return intellect;
            if (index == Abilities.Luck)
                return luck;
            throw new System.IndexOutOfRangeException();
        }

        private void SetAbilityScore(Abilities index, int value)
        {
            if (index == Abilities.Strength)
                Strength = value;
            else if (index == Abilities.Stamina)
                Stamina = value;
            else if (index == Abilities.Agility)
                Agility = value;
            else if (index == Abilities.Speed)
                Speed = value;
            else if (index == Abilities.Intellect)
                Intellect = value;
            else if (index == Abilities.Luck)
                Luck = value;
            else
                throw new System.IndexOutOfRangeException();
        }
    }
}